package com.bdqn.service.impl;

import com.bdqn.mapper.HisCareHistoryMapper;
import com.bdqn.pojo.HisCareHistory;
import com.bdqn.service.HisCareHistoryService;
import com.bdqn.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Service
public class HisCareHistoryServiceImpl implements HisCareHistoryService {
    @Autowired
    HisCareHistoryMapper hisCareHistoryMapper;
    @Autowired
    RandomUtil randomUtil;

    @Override
    public int addHisCareHistory(HisCareHistory hisCareHistory) {
        String chId = randomUtil.randomChId();
        hisCareHistory.setChId(chId);

        // 获取当前的日期和时间
        LocalDateTime currentDateTime = LocalDateTime.now();
        // 定义日期时间的格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 将当前日期和时间按照指定的格式转换为字符串
        String formattedDateTime = currentDateTime.format(formatter);
        hisCareHistory.setCareDate(formattedDateTime);

        return hisCareHistoryMapper.addHisCareHistory(hisCareHistory);
    }

    @Override
    public String getChId(String id) {
        return hisCareHistoryMapper.selectChId(id);
    }
}
